/***************************************************************************
 *   Copyright (C) 2008 by Łukasz Spintzyk   *
 *   lukasz.spintzyk@gmail.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
/*!Set of functions for drawing menu, lines, and all necesarry things which will be displayed on oscilloscope screen.
 */

#ifndef DISPLAY_H
#define DISPLAY_H
#include <inttypes.h>
#include <avr/pgmspace.h>
#include "device_opt.h"
#include "t6963.h"
#include "digital_oscilloscope.h"


#ifndef FONT_SIZE
#define FONT_SIZE 6
#endif

//!Display SIZE 240x64
#define DSIZE_W	240
#define DSIZE_H	64

//! Size of info part od display in columns 
#define DINFO_SIZE_W	11
#define DINFO_SIZE_H   64

//!Size of data part of display in pixels
#define DDATA_AREA_SIZE_W (DSIZE_W - (DINFO_SIZE_W * FONT_SIZE))
#define DDATA_AREA_SIZE_H DSIZE_H

//!Size of one div on display in pixels
//! \todo Maybe 6 will be easier to draw since we have 6 pixel font size.
#define TDIV_W 10
#define UDIV_H 10

//!Starting adres of info screen in colls
#define DINFOX0	(DSIZE_W/FONT_SIZE - DINFO_SIZE_W)
#define DINFOY0	0


extern uint8_t screen_memorych1[DDATA_AREA_SIZE_W/FONT_SIZE+1];
extern uint8_t screen_memorych2[DDATA_AREA_SIZE_W/FONT_SIZE+1];

//! Function draw time and voltage scale
void drawGrid(uint16_t baseaddres);

void drawCursors();

extern unsigned char lcd_y;
extern unsigned char lcd_x;
void drawChannel(uint8_t num);

/*! Function draws oscilloscope menu
 */
void drawInfo();

/*! Function uses builit in  lcd_drive cursor.
 * \param visible set visibility of cursor
 * \param n_lines height of cursor form 1 to 8 pixels
 * \param blink sets blinking of cursor
 * \param x number of column
 * \param y number of row
 */
void showTextCursor(bool visible, uint8_t n_lines, bool blink, uint8_t x, uint8_t y);

/*! Function draw line on display
 * \param begin - starting point of line
 * \param end -ending point of line
 * \param off - if true line from begin to end schould be erased
 */
void drawLine(upoint8_t begin, upoint8_t end, bool off);


/*! Draws information text SET, that informes that user pressed setButton.
 * \deprecated Because I will use blinking Cursor which is build into lcd drive
 * \param if true then SET is drawn, else erased
 */
//void drawSET(bool);

/*! this function draw character at lcd_y, lcd_x.
 * \deprecated Because lcd drive have builit in character generator.
 */
//void lcdWriteChar2(char a, bool neg);

/*! Writes String from program memory
 *  \deprecated
 */
//void lcdWriteStringPGM2(char *str,bool neg);
/*! this function draw character at lcd_y, lcd_x.
 * \deprecated Because lcd drive have builit in character generator.
 */
//void lcdWriteString2(char *str,bool neg);


/*! Function which parse integer value to string
 * \todo finish it
 */
void displayValue(upoint8_t where, int16_t val,char * unit);
void displayRadixValue(upoint8_t where, int16_t val,uint8_t radix);
void sendToDisplay(int8_t);


//upoint_t vPoint,tPoint, adjustFreqPoint, UPoint, TPoint, XYPoint, CH1Point, CH2Point, ADDPoint;//!< Zmienne pomocnicze - wsp�?rz?dne danych na wy?wietlaczu

//! Constants which describes positions of menu options on screen
#define VOLTPERDIV_X DINFOX0
#define VOLTPERDIV_Y DINFOY0+0

//!TIMEPERDIV_VALUE_X means where we schould print voltage div on menu
#define VOLTPERDIV_VALUE_X VOLTPERDIV_X+6


#define TIMEPERDIV_X DINFOX0
#define TIMEPERDIV_Y DINFOY0+1
#define TIMEPERDIV_VALUE_X TIMEPERDIV_X+6



#define VOLTCURSOR_X DINFOX0
#define VOLTCURSOR_Y DINFOY0+2
#define VOLTCURSOR_VALUE_X VOLTCURSOR_X+3



#define TIMECURSOR_X DINFOX0
#define TIMECURSOR_Y DINFOY0+3
#define TIMECURSOR_VALUE_X TIMECURSOR_X+3



#define CURSORX1_X DINFOX0
#define CURSOR_Y  DINFOY0+4

#define CURSORY1_X CURSORX1_X+3

#define CURSORX2_X CURSORY1_X+3

#define CURSORY2_X CURSORX2_X+3


#define CH1_X DINFOX0
#define CH1_Y DINFOY0+5

#define CH2_X DINFOX0
#define CH2_Y DINFOY0+6


#define AC_X CH2_X+4
#define AC_Y DINFOY0+6

#define ADD_X DINFOX0
#define ADD_Y DINFOY0+7

#define SUB_X ADD_X+4
#define SUB_Y DINFOY0+7

#define FR_X SUB_X+4
#define FR_Y DINFOY0+7

#endif
